package com.hzhq.contract.convert.method;

import com.hzhq.contract.bean.dto.UserRoleDTO;
import com.hzhq.contract.bean.entity.UserRole;
import com.hzhq.contract.bean.vo.UserRoleVO;
import com.hzhq.contract.status.DefaultValue;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hzhq
 * @create 2021/4/10 4:45 下午
 * @email hzhq1255@163.com
 */
public class UserConvertMethod {

    private static List<UserRole> filterPassedRoleList(List<UserRole> userRoleList) {
        List<UserRole> userRolePassedList = new ArrayList<>();
        if (null != userRoleList) {
            for (UserRole userRole : userRoleList) {
                if (userRole.getPassed() == 1 && userRole.getDeleted() == 0) {
                    userRolePassedList.add(userRole);
                }
            }
        }
        return userRolePassedList;
    }


    public static List<UserRoleVO> entityList2VOList(List<UserRole> userRoleList) {
        userRoleList = filterPassedRoleList(userRoleList);
        List<UserRoleVO> voList = new ArrayList<>();
        voList = userRoleList.stream().map(item -> UserRoleVO.builder()
                .role(item.getRole().getRoleName())
                .admin(item.getAdmin().getAdminName())
                .assignTime(item.getAssignTime())
                .passed(item.getPassed())
                .deleted(item.getDeleted())
                .build()
        ).collect(Collectors.toList());
        return voList;
    }


}
